package com.ee.chat.admin.controller.channelmanage;

import com.ee.chat.admin.service.IChannelService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.vo.ChannelVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("channel")
public class ChannelController {
    private Logger log= LoggerFactory.getLogger(ChannelController.class);

    @Resource
    IChannelService channelService;

    /**
     * 渠道列表
     * @Author Shane
     * @Date 2019/11/23 16:29
     * @param
     * @return
     **/
    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit, String keyword, Integer type){
        try {
            return channelService.list(request, page, limit, keyword, type);
        } catch (Exception e){
            log.error("【获取渠道列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑渠道
     * @Author Shane
     * @Date 2019/11/23 16:29
     * @param
     * @return
     **/
    @RequestMapping("toEdit")
    public Result toEdit(HttpServletRequest request, @RequestParam(required = false) Integer id){
        try {
            return channelService.toEdit(request, id);
        } catch (Exception e){
            log.error("【编辑渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 新增渠道
     * @Author Shane
     * @Date 2019/11/23 16:52
     * @param
     * @return
     **/
    @RequestMapping("add")
    public Result add(HttpServletRequest request, ChannelVO channel){
        try {
            return channelService.add(request, channel);
        } catch (Exception e){
            log.error("【新增渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存渠道
     * @Author Shane
     * @Date 2019/11/23 16:52
     * @param
     * @return
     **/
    @RequestMapping("edit")
    public Result edit(HttpServletRequest request, ChannelVO channel){
        try {
            return channelService.edit(request, channel);
        } catch (Exception e){
            log.error("【保存渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新渠道状态
     * @Author Shane
     * @Date 2019/9/1118:12
     * @param id    用户id
     * @return
     **/
    @RequestMapping("updateStatus")
    public Result updateStatus(HttpServletRequest request, @RequestParam Integer id){
        try {
            return channelService.updateStatus(request, id);
        } catch (Exception e){
            log.error("【更新渠道状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取渠道统计数据
     * @Author Shane
     * @Date 2019/11/26 11:06
     * @param
     * @return
     **/
    @RequestMapping("statis")
    public Result statis(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit,
                         Integer userId, String code, String createTime){
        try {
            return channelService.statis(request, page, limit, userId, code, createTime);
        } catch (Exception e){
            log.error("【获取渠道统计错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 重置渠道用户密码
     * @Author AppiJ
     * @Date 2020/4/20 13:34
     * @param
     * @return
     */
    @RequestMapping("restPwd")
    public Result restPwd(HttpServletRequest request, @RequestParam Integer id){
        try {
            return channelService.restPwd(request, id);
        } catch(Exception e){
            log.error("【重置渠道用户密码错误】", e);
        }
        return Result.returnFailure();
    }
}